#include "Box2DWorld.h"
#include "Time.h"

namespace impl
{
	Box2DWorld* _instance = nullptr;
}

mtBEGIN(Box2DWorld)
	mtBASE(ECS::Component);
	mtMETHOD(onUpdate);
mtEND

Box2DWorld::Box2DWorld()
{
	impl::_instance = this;
}

bool Box2DWorld::initWith(Box2DWorldDef* def)
{
	_world = new b2World(def->gravity);
	return true;
}

Box2DWorld* Box2DWorld::getInstance()
{
	return impl::_instance;
}

void Box2DWorld::onUpdate()
{
	_world->Step(Time::deltaTime, 5, 5);
	_world->ClearForces();
}

b2World* Box2DWorld::getWorld() const
{
	return _world;
}

Box2DWorldDef::Box2DWorldDef() : gravity(0.0f, 0.0f)
{

}
